using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.ProjectApp
{
    public partial class TeachingReform : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) 
            {
                DataBinds();
               
            }
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            LabMS.BLL.TeachingReform Reform = new LabMS.BLL.TeachingReform();
            LabMS.Model.TeachingReform ReformItem = new LabMS.Model.TeachingReform();
            ReformItem.Teach_Address = tb_Addres.Text;
            ReformItem.Teach_InCharge = tb_InCharge.Text;
            ReformItem.Teach_Mail = tb_Email.Text;
            ReformItem.Teach_ProjectName = tb_ProjectName.Text;

            ReformItem.Teach_UnitName = tb_UnitName.Text;
            ReformItem.Teach_UnitType = rbl_UnitType.SelectedValue;

            ReformItem.Teach_Phone = tb_Phone.Text;
            ReformItem.Teach_Time = DateTime.Now;

            ReformItem.Teach_DocType = ddl_ProjectType.SelectedValue.Trim();

            string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/");
            string Append = DateTime.Now.ToString("yyyyMMddhhmmss");
            string FullPathFileName = savePath.Trim() + Append.Trim()+"_" + fp_Attach.FileName.Trim();
            int attachID = 0;
            bool save = true;
            if (fp_Attach.HasFile) 
            {
                try
                {
                    
                    fp_Attach.SaveAs(FullPathFileName);

                }
                catch 
                {
                    save = false;
                    throw new Exception("File Save Error");
                }
            }
            if (save)
            {
                LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment();
                LabMS.Model.Attachment attach = new LabMS.Model.Attachment();
                attach.Attach_Name = fp_Attach.FileName;
                attach.Attach_Address = FullPathFileName;
                attachID = Attach.Add(attach);
                
                
            }
            if(attachID!=0)
            {
                ReformItem.Teach_Attachment=attachID;
            }
            Reform.Add(ReformItem);

            Response.Redirect(@"\ProjectApp\TeachingReformList.aspx");
        }
        protected void DataBinds() 
        {
            LabMS.BLL.DictionaryClass DicClass = new LabMS.BLL.DictionaryClass();
            LabMS.BLL.Dictionary Dic = new LabMS.BLL.Dictionary();


            List<LabMS.Model.Dictionary> lsDic = new List<LabMS.Model.Dictionary>();
            LabMS.Model.DictionaryClass Ds = new LabMS.Model.DictionaryClass();

			
            Ds = DicClass.GetModelList("Code= 'TeachingReform'")[0];
            lsDic = Dic.GetModelList("DClass='" + Ds.Code + "'");

            ddl_ProjectType.DataSource = lsDic;
            ddl_ProjectType.DataValueField = "Code";
            ddl_ProjectType.DataTextField = "Name";
            ddl_ProjectType.DataBind();


            Ds = DicClass.GetModelList("Code='UnitType'")[0];
            lsDic = Dic.GetModelList("DClass='" + Ds.Code + "'");
            rbl_UnitType.DataSource = lsDic;
            rbl_UnitType.DataTextField = "Name";
            rbl_UnitType.DataValueField = "Code";
            rbl_UnitType.DataBind();

        }
    }
}
